package closure

// 返回一个“返回int的函数”
func Fibonacci() func() int {
	result1 := 0
	result2 := 0
	n := 0
	return func() (result int) {

		if n >= 0 && n < 2 {
			result = n
		} else if n < 0 {
			result = 0
		} else {
			result = result1 + result2
		}
		result1 = result2
		result2 = result
		n++
		return
	}
}

func Fib2(n int) int {
	if n >= 0 && n < 2 {
		return n
	} else if n < 0 {
		return 0
	} else {
		return Fib2(n-2) + Fib2(n-1)
	}
}
